import config from './config.js'

export default  (url,data={},method='GET')=>{
  return new Promise((resolve,reject)=>{
    wx.request({
      url: `${config.mpHost}${url}`,
      data,
      method,
      header:{
        cookie:wx.getStorageSync('cookie')
      },
      success: (res) => {
        if (data._isLogin){
          console.log(res)
          const cookie=res.cookies.find(cookie=>cookie.startsWith('MUSIC_U'))
          console.log(cookie)

          wx.setStorageSync('cookie',cookie)
        }
        resolve(res.data)
      }
    })
  })
}